import time

from selenium.webdriver.common.by import By

from baseutil.Util import BoxDriver
class RanzhiLogin:

    def login (self,url,account,password,boxd:BoxDriver):

        boxd.get(url)
        boxd.implicitly_wait(10)
        boxd.input(By.ID, "account", account)
        boxd.input(By.ID, "password",password)
        boxd.click(By.ID, "submit")
        time.sleep(2)

    def loginsuccess(self,expect,boxd:BoxDriver):
        time.sleep(2)
        username = boxd.find_element(By.XPATH,'//*[@id="mainNavbar"]/div/ul[1]/li').text
        assert username == expect
        time.sleep(2)

    def loginfail(self,boxd:BoxDriver):
        time.sleep(2)
        tips = boxd.find_element(By.XPATH,'/html/body/div[2]/div/div/div[1]/div').text
        assert tips == "登录失败，请检查您的成员名或密码是否填写正确。"
        boxd.find_element(By.XPATH,"/html/body/div[2]/div/div/div[2]/button").click()

    def logout(self,boxd:BoxDriver):
        time.sleep(2)
        boxd.find_element(By.XPATH,'//*[@id="bottomRightBar"]/ul/li[1]').click()

